Carbon


WritePartialResource

Header: Resources.h Carbon status: Supported

Writes part of a resource to disk when working with a small subsection of a large resource.

void WritePartialResource (
    Handle theResource, 
    SInt32 offset, 
    const void *buffer, 
    SInt32 count
);
theResource

A handle to the resource you wish to write to disk.

offset

The beginning of the resource subsection to write, measured in bytes from the beginning of the resource.

buffer

A pointer to the buffer containing the data to write. Your application is responsible for the buffer’s memory management.

count

The length of the resource subsection to write.

DISCUSSION

If the disk or the file is locked, the ResError function returns an appropriate File Manager result code. If you try to write past the end of a resource, the Resource Manager attempts to enlarge the resource. The ResError function returns the result code writingPastEnd if the attempt succeeds. If the Resource Manager cannot enlarge the resource, ResError returns an appropriate File Manager result code. If you pass an invalid value in the offset parameter, ResError returns the result code inputOutOfBounds.

This function tries to write the data from the buffer to disk. If the attempt is successful and the resource data (referenced through the resource’s handle) is in memory, ResError returns the result code resourceInMemory. In this situation, be aware that the data of the resource subsection on disk matches the data from the buffer, not the resource data referenced through the resource’s handle. If the attempt to write the data from the buffer to the disk fails, ResError returns an appropriate error.

When using partial resource functions, you should call the SetResLoad function, specifying FALSE for the load parameter, before you call the GetResource function. Doing so prevents the Resource Manager from reading the entire resource into memory. Be sure to restore the normal state by calling SetResLoad again, with the load parameter set to TRUE, immediately after you call GetResource.

If you read a partial resource into memory and then change its size, you must use the SetResourceSize function to change the entire resource’s size on disk as necessary before you write the partial resource.

SPECIAL CONSIDERATIONS

This function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

AVAILABILITY

Supported in Carbon. Available in Mac OS 8.1 and later when Carbon 1.0.2 or later is present.


© 2000 Apple Computer, Inc. — (Last Updated 5/8/2000)